<?php
/**
 * This is Areas controller test file. 
 *
 * @copyright     Copyright 2008-2010, LilCake.net
 * @link          http://lilcake.net LilCake.net
 * @package       lil
 * @subpackage    lil.tests.cases.controllers
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
/**
 * AreasControllerTestCase class
 *
 * @package       lil
 * @subpackage    lil.tests.cases.controllers
 */
class AreasControllerPlainTestCase extends ControllerTestCase {
/**
 * fixtures property
 *
 * @var array
 */
	public $fixtures = array(
		'plugin.lil.area', 'plugin.lil.areas_user', 'plugin.lil.user'
	);
/**
 * setUp method
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		// reset variables
		require dirname(dirname(dirname(dirname(__FILE__)))) . DS . 'Config' . DS . 'core.php';
		
		Configure::write('Lil.noAreas', array(
			'0' => array('Area' => array('id' => 1, 'slug' => 'first', 'title' => 'Test 1')),
			'1' => array('Area' => array('id' => 2, 'slug' => 'second', 'title' => 'Test 2')),
		));
	}
/**
 * tearDown method
 *
 * @return void
 */
	public function tearDown() {
		ClassRegistry::flush();
		parent::tearDown();
	}
/**
 * testIndex method
 *
 * @access public
 * @return void
 */
	function testIndex() {
		////////////////////////////////////////////////////////////////////////////////////////////
		// 1. check normal index
		////////////////////////////////////////////////////////////////////////////////////////////
		$Areas = $this->generate('Lil.Areas');
		$this->testAction('lil/areas/index');
		$this->assertTrue(empty($this->headers['Location']));
		
		////////////////////////////////////////////////////////////////////////////////////////////
		// 2. check index with single area
		////////////////////////////////////////////////////////////////////////////////////////////
		
		// delete all areas but the first one:
		$areas = Configure::read('Lil.noAreas');
		Configure::write('Lil.noAreas', array('0' => $areas[0]));
		
		$this->testAction('lil/areas/index');
		$this->assertTrue(!empty($this->headers['Location']));
		
		$expected_url = Router::url($this->headers['Location'], true);
		$this->assertEqual(Router::url(array(
			'admin'      => false,
			'plugin'     => 'lil',
			'controller' => 'areas',
			'action'     => 'index',
			'area'       => 'first'
		), true), $expected_url);
	}
/**
 * testView method
 *
 * @access public
 * @return void
 */
	function testView() {
		$Areas = $this->generate('Lil.Areas');
		$this->testAction('lil/areas/view/first');
		
	}
/**
 * testAdminIndex method
 *
 * @access public
 * @return void
 */
	function testAdminIndex() {
		$Areas = $this->generate('Lil.Areas', array(
			'loadRoutes' => false,
			'components' => array(
				'Session'
			),
			'methods' => array(
				'isAuthorized',
				'redirect'
			),
		));
		$this->testAction('admin/lil/areas/index');
	}
/**/
}